package main

import (
	"fmt"
	"sync"
)

func print交替(numberChan, letterChan chan<- interface{}, wg *sync.WaitGroup) {
	defer wg.Done()
	for i := 1; i <= 5; i++ {
		numberChan <- i
		letterChan <- rune('A' + i - 1)
	}
	close(numberChan)
	close(letterChan)
}

func main() {
	var wg sync.WaitGroup

	// 创建两个通道
	numberChan := make(chan interface{})
	letterChan := make(chan interface{})

	// 使用一个goroutine来控制交替打印
	wg.Add(1)
	go print交替(numberChan, letterChan, &wg)

	// 交替读取并打印数字和字母
	for {
		select {
		case number, ok := <-numberChan:
			if !ok {
				goto LETTERS_DONE
			}
			fmt.Print(number, ", ")
		case letter, ok := <-letterChan:
			if !ok {
				goto NUMBERS_DONE
			}
			fmt.Printf("%c, ", letter)
		}
	}
NUMBERS_DONE:
LETTERS_DONE:
	wg.Wait()     // 确保goroutine执行完毕
	fmt.Println() // 打印换行符结束
}
